package com.hfjyz.registration.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;

import com.hfjyz.registration.command.ModifyPasswordCommand;
import com.hfjyz.registration.contants.ExamContants;
import com.hfjyz.registration.model.Exam;
import com.hfjyz.registration.service.RegistService;

public class ModifyPasswordController extends SimpleFormController {

	private RegistService registService;

	@Override
	protected ModelAndView onSubmit(HttpServletRequest request,
			HttpServletResponse response, Object command, BindException errors)
			throws Exception {
		ModifyPasswordCommand cmd = (ModifyPasswordCommand) command;
		Exam exam = (Exam) request.getSession().getAttribute(
				ExamContants.SESSION_KEY_EXAM_INFO);
		cmd.setExam(exam);
		if (!errors.hasErrors()) {
			registService.loggin(request, ExamContants.LOGING_TYPE_INFO,
					(Integer) null, ExamContants.LOGING_USER_TYPE_USER,
					cmd.getIdCardNo(), ExamContants.LOGING_OP_TYPE_EDIT,
					"修改密码");
			registService.modifyPassword(cmd, errors);
		}
		if (errors.hasErrors()) {
			return new ModelAndView(getFormView(), errors.getModel());
		} else {
			return new ModelAndView(getSuccessView(), errors.getModel());
		}
	}

	/**
	 * @return the registService
	 */
	public RegistService getRegistService() {
		return registService;
	}

	/**
	 * @param registService
	 *            the registService to set
	 */
	public void setRegistService(RegistService registService) {
		this.registService = registService;
	}

}